<?php

namespace App\Strategies;

use App\Helpers\DateUtils;
use App\Helpers\LinkUtils;
use App\Services\Core\Store\Qiniu\QiniuService;
use App\Strategies\AppStrategy;

/**
 * 公共策略
 *
 * @package App\Strategies
 */
class FavouriteStrategy extends AppStrategy
{
    /**
     * @param $productArr
     * 产品——产品收藏列表数据处理
     */
    public static function getCollectionLists($type, $product, $countPage)
    {
        foreach ($product as $key => $val) {
            $product[$key]['position_sort'] = $val['position_sort'];
            $rate                           = $val['composite_rate'];
            $speed                          = $val['loan_speed'];
            $exper                          = $val['experience'];
            $star                           = bcdiv(bcadd($exper, bcadd($rate, $speed)), 3, 1);
            $product[$key]['star']          = !empty($star) ? $star : '4.0';
            $product[$key]['product_logo']  = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
            $product[$key]['tag_name']      = !empty($val['tag_name']) ? $val['tag_name'] : array();
            $product[$key]['success_count'] = DateUtils::ceilMoney($val['success_count']);
            $product[$key]['productType']   = intval($type);
            $product[$key]['sign']          = 1;
        }
        $dataAll['list']      = $product;
        $dataAll['pageCount'] = $countPage;
        return $dataAll;
    }

    /**
     * @param $newsArr
     * @param $pageCount
     * 资讯——资讯收藏列表数据处理
     */
    public static function getCollectionNewsLists($newsArr, $data)
    {
        $pageSize = isset($data['pageSize']) ? intval($data['pageSize']) : 1;
        $pageNum  = isset($data['pageNum']) ? intval($data['pageNum']) : 10;

        $newsData = [];
        foreach ($newsArr as $key => $val) {
            $newsData[$key]['id']                 = $val['id'];
            $newsData[$key]['title']              = $val['title'];
            $newsData[$key]['cover_img']          = QiniuService::getInfoImgs($val['cover_img']);
            $newsData[$key]['create_time']        = DateUtils::formatDate($val['create_time']);
            $newsData[$key]['is_collection']      = 1;
            $newsData[$key]['footer_img_h5_link'] = empty($val['footer_img_h5_link']) ?
                LinkUtils::appLink($val['id']) : $val['footer_img_h5_link'];
            $newsData[$key]['footer_img_h5']      = $val['footer_img_h5_link'];
        }
        //分页
        $newsLists = DateUtils::pageInfo($newsData, $pageSize, $pageNum);
        return $newsLists ? $newsLists : [];
    }
}
